project ('nico', 'vala', 'c')

pkgconfig = import('pkgconfig')
gnome = import('gnome')

nico_lib_dep = [
   dependency('glib-2.0'),
   dependency('gio-2.0'),
   dependency('json-glib-1.0'),
   dependency('gtk+-3.0'),
]


nico_resources = gnome.compile_resources(
                        'nico-resources',
                        meson.current_source_dir()+'/data/de.grindhold.nico.gresource.xml',
                        source_dir: 'data')

nico_lib_src = [
    'src/connection_handler.vala',
    'src/server.vala',
    'src/types.vala',
    'src/client.vala'
]

nico_server_src = [
    'src/serverapp.vala'
]

nico_client_src = [
    'src/clientapp.vala'
]

libversion = '0.2.0'
api = '0.2'

valagir = 'Nico-' + api + '.gir'

nico_lib = shared_library('nico-'+api, nico_lib_src,
            dependencies: nico_lib_dep,
            install: true,
            version: libversion,
            vala_gir: valagir)

g_ir_compiler = find_program('g-ir-compiler')

custom_target('nico-typelib',
               command: [g_ir_compiler, '--output', '@OUTPUT@', valagir, '--shared-library', 'libnico-' + api + '.so'],
               output: 'Nico-' + api + '.typelib',
               depends: nico_lib,
               install: true,
               install_dir: get_option('libdir') + '/girepository-1.0')


nico_server = executable('nico-server', nico_server_src,
                    dependencies: nico_lib_dep,
                    link_with: nico_lib,
                    install:true,
                    vala_args: ['--target-glib=2.38'])

nico_client = executable('nico-client', nico_client_src, nico_resources,
                    dependencies: nico_lib_dep,
                    link_with: nico_lib,
                    install:true,
                    vala_args: ['--target-glib=2.38'])

if get_option('enable_valadoc')
	valadoc = find_program('valadoc')
	custom_target('apidocs',
                   input: nico_lib_src,
                   command: [valadoc, '-o', 'devhelp/nico-'+api, '--doclet', 'devhelp', '@INPUT@',
                   '--force', '--pkg', 'json-glib-1.0'],
                   output: 'devhelp',
                   build_by_default: true)
  install_subdir(meson.current_build_dir()+'/devhelp/nico-'+api+'/nico-'+api,
                 install_dir: get_option('datadir')+'/devhelp/books')
endif
